<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjXm']" placeholder="请输入姓名"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjXb']" placeholder="请输入性别"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="出生地" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjCsd']" placeholder="请输入出生地"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="民族" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjMz']" placeholder="请输入民族"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="出生年月" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择出生年月" v-decorator="['zjCsny']" :trigger-change="true" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="行政职务" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjXzzw']" placeholder="请输入行政职务"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="国家" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjGj']" placeholder="请输入国家"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjSfzh']" placeholder="请输入身份证号"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="工作单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjGzdw']" placeholder="请输入工作单位"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="办公电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjBgdh']" placeholder="请输入办公电话"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="通讯地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjTxdz']" placeholder="请输入通讯地址"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="邮编" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjYb']" placeholder="请输入邮编"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="邮箱" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjYx']" placeholder="请输入邮箱"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="手机（登录账号）" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjSj']" placeholder="请输入手机（登录账号）"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="毕业院校" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjByyx']" placeholder="请输入毕业院校"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="文化程度" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjWhcd']" placeholder="请输入文化程度"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="技术职称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjJszc']" placeholder="请输入技术职称"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="专业职称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjZyzc']" placeholder="请输入专业职称"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="毕业时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择毕业时间" v-decorator="['zjBysj']" :trigger-change="true" style="width: 100%" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="所属集团" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjSsjt']" placeholder="请输入所属集团"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="登录密码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjPassword']" placeholder="请输入登录密码"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="权限" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjQx']" placeholder="请输入权限"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="所属类别" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['zjLb']" placeholder="请输入所属类别"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="微信unionid" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['unionid']" placeholder="请输入微信unionid"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="微信openid" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['openid']" placeholder="请输入微信openid"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="是否有效" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-switch v-decorator="['isValid']"  ></j-switch>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="备用" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['bak1']" placeholder="请输入备用"  ></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="可否登录" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-switch v-decorator="['isLogin']"  ></j-switch>
            </a-form-item>
          </a-col>
          <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'SysCxjZjForm',
    components: {
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        form: this.$form.createForm(this),
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/cxj/sysCxjZj/add",
          edit: "/cxj/sysCxjZj/edit",
          queryById: "/cxj/sysCxjZj/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'zjXm','zjXb','zjCsd','zjMz','zjCsny','zjXzzw','zjGj','zjSfzh','zjGzdw','zjBgdh','zjTxdz','zjYb','zjYx','zjSj','zjByyx','zjWhcd','zjJszc','zjZyzc','zjBysj','zjSsjt','zjPassword','zjQx','zjLb','unionid','openid','isValid','bak1','isLogin'))
        })
      },
      //渲染流程表单数据
      showFlowData(){
        if(this.formBpm === true){
          let params = {id:this.formData.dataId};
          getAction(this.url.queryById,params).then((res)=>{
            if(res.success){
              this.edit (res.result);
            }
          });
        }
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'zjXm','zjXb','zjCsd','zjMz','zjCsny','zjXzzw','zjGj','zjSfzh','zjGzdw','zjBgdh','zjTxdz','zjYb','zjYx','zjSj','zjByyx','zjWhcd','zjJszc','zjZyzc','zjBysj','zjSsjt','zjPassword','zjQx','zjLb','unionid','openid','isValid','bak1','isLogin'))
      },
    }
  }
</script>